<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Display extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('file');
        $this->load->library('topclass');
        $this->load->helper('fuc');
        $this->config->load('topapiconfig');
        $this->load->database();
        $this->load->model('memmbers');
    }

    public function genarray($usernick) {//这步生成数组
        $resp = $this->topclass->api_getSellercatsListGetRequest("SellercatsListGetRequest", $usernick, $sessionkey = null);
        objectToArray(&$resp);
        return $resp;
    }

    public function index() {
        redirect("display/show", 'location');
    }

    public function show() {

		decis_last_time();
//        if (!isset($_SESSION["statue"])) {
//            $url = site_url("login/index");
//            redirect($url, 'location');
//        }     
        //$_SESSION["serverarray"] = getserverarray($_SESSION["usernick"], $_SESSION["sessionkey"]);

          if (!isset($_SESSION["statue"])) {
				$url = site_url("login/index");
				redirect($url, 'location');
        	}

        $data['menu'] = 'index';
        $sql = "select * from join_memebers order by id desc limit 30";
        $query = $this->db->query($sql);
        $res = $query->result_array();
        $data['members'] = $res;
        $data['userleve'] = $this->memmbers->get_user_level();

        $this->load->view('header_view', $data);
        $this->load->view('index_view');
        $this->load->view('footer_view');
    }

    public function category() {
        if (!isset($_SESSION["statue"])) {
            $url = site_url("login/index");
            redirect($url, 'location');
        }
        decis_last_time();
	    $data['tmpcounts'] = get_shop_tmpcounts($_SESSION["shopid"]);
        $data['menu'] = 'category';
        $data['userleve'] = $this->memmbers->get_user_level();
        $data['filesarray'] = get_filenames('modules/imgs_category');
        $this->load->view('header_view', $data);
        $this->load->view('category_view');
        $this->load->view('footer_view');
    }

    /*     * ****************************************************************
     *  制作 旺旺客服模块
     */

    public function wangwang() {
        if (!isset($_SESSION["statue"])) {
            $url = site_url("login/index");
            redirect($url, 'location');
        }decis_last_time();
        $data['tmpcounts'] = get_shop_tmpcounts($_SESSION["shopid"]);
        $data['menu'] = 'wangwang';
        $data['userleve'] = $this->memmbers->get_user_level();
        $data['filesarray'] = get_filenames('modules/imgs_wangwang');
        $this->load->view('header_view', $data);
        $this->load->view('wangwang_view');
        $this->load->view('footer_view');
    }

    /*     * ****************************************************************
     *  制作 综合模块
     */

    public function service() {
        if (!isset($_SESSION["statue"])) {
            $url = site_url("login/index");
            redirect($url, 'location');
        }
		decis_last_time();
        $data['tmpcounts'] = get_shop_tmpcounts($_SESSION["shopid"]);
        $data['menu'] = 'service';
        $data['userleve'] = $this->memmbers->get_user_level();
        $filesarray = get_filenames('modules/imgs_service');
		$data['filesarray'] = array_reverse($filesarray);
		
        $this->load->view('header_view', $data);
        $this->load->view('service_view');
        $this->load->view('footer_view');
    }

    public function template($moduleType = '', $modl_name = '') {
        $data['moduleType'] = $moduleType;
        $data['modl_name'] = $modl_name;
        $data['rrr'] = $this->genarray($_SESSION["usernick"]);
        if (empty($data['rrr'])) {
            echo "<script language=\"javascript\">alert(\"您的店铺还没有分类，请设置淘宝店铺分类：）\")</script>";
            exit;
        }
        $sellarray = $data['rrr']["seller_cats"]["seller_cat"];
		
		$data['colors'] = f100colors();
		$data['snsArr'] = f100sns();
		$data['say'] = f100say();
		
        if($data['moduleType'] == 'wangwang'){
			$data['wangwang'] = generatewanwagarray($_SESSION["shopid"]);
			$data['wangwang_small'] = $data['wangwang'];
		}elseif($data['moduleType'] == 'category'){
			$data['test_cats'] =  chagearray2($sellarray);
		}else{
			$data['wangwang'] = generatewanwagarray($_SESSION["shopid"]);
			$data['test_cats'] =  chagearray2($sellarray);
		}
		
        $data['redirectudl'] = site_url("tmpmanage");
        $this->load->view('template_view', $data);
    }

    public function initialize() {
        $this->load->model('service');
        $this->service->import_data_new();	
    }

	//登录验证
    public function actionlogin() {//验证授权参数，赋予session值
       /* 
http://100.ipropre.com/index.php/display/actionlogin?code=WkhoWp2NoqF172VypouVBpNy262741&state=scope%3Ar1%2Cr2%2Cw1%2Cw2%3Bsign%3AF3C0F327F3473C5C7B882DEB508A4DC3%3BleaseId%3A43870%3Btimestamp%3A1347960058904%3BversionNo%3A1%3BitemCode%3Ats-1810466-1	
		http://100.ipropre.com/index.php/display/actionlogin?code=WkhoWp2NoqF172VypouVBpNy262741&state=scope:r1,r2,w1,w2;sign:F3C0F327F3473C5C7B882DEB508A4DC3;leaseId:43870;timestamp:1347960058904;versionNo:1;itemCode:ts-1810466-1
		*/

		if( !isset($_GET['top_parameters'])){
			redirect('login/logout', 'location', 301);
		}
		
		$this->load->library('parameter', array("get" => $_GET["top_parameters"]));
        $top_parameters_array = $this->parameter->getParamArray();
        $usernick = $top_parameters_array["visitor_nick"]; //通过链接获得用户昵称        
        $_SESSION["usernick"] = $usernick;
        $_SESSION["shopid"] = getshopid($_SESSION["usernick"]);
        $top_appkey = $_GET["top_appkey"];
        $top_parameters = $_GET["top_parameters"];
        $top_session = $_GET["top_session"];
        $_SESSION["sessionkey"] = $top_session;
        //   print_r($_SESSION["sessionkey"]);
        //  exit;
        $appsetingarray = $this->config->item('zwbtj2012');
        $secret = $appsetingarray["behidend"]["appsecck"];
        $top_sign = $_GET["top_sign"];
        $sign = base64_encode(md5($top_appkey . $top_parameters . $top_session . $secret, true));

        // $sign =frontlogin();
        if ($sign != $top_sign) {
            echo "签名错误";
            //跳转链接
            redirect('login/index', 'location', 301);
            exit();
        } else {
            $this->initialize();
            $this->joinmemeber();
           $_SESSION['last_active_time'] = time();//获取登陆时候时间戳
            $_SESSION["statue"] = "login"; //如果登陆赋予session状态；
            redirect('display/show', 'location', 301);
        }
    }

 
	public function savetmp() {
        
        if (!isset($_SESSION["statue"])) {
            $url = site_url("login/index");
            redirect($url, 'location');
        }
		decis_last_time();
		
        $width = get_tmp_width($_POST["tmpath"]);
        $time = time();
        $htmlcontent=urldecode($_POST["htmlcontent"]);//与js对应第一次解码 
         
     $htmlcontent = htmlspecialchars($htmlcontent);//第二次编码为了存入数据库中
       
        $insertsql = "INSERT INTO res (shopid,time,content,width,tmpname,staute,tmpath) VALUES (
        \"{$_SESSION["shopid"]}\",\"{$time}\",
         \"{$htmlcontent}\",\"{$width}\",\"{$_POST["tmpname"]}\",0,\"{$_POST["tmpath"]}\")";
        $this->db->query($insertsql);
    }
	
/*  
    public function savetmp() {
        if (!isset($_SESSION["statue"])) {
            $url = site_url("login/index");
            redirect($url, 'location');
        }
		decis_last_time();

        $time = time();
		echo $htmlcontent = $this->input->post('saveToDatabaseCode');
		//$htmlcontent = $_POST["saveToDatabaseCode"];
		$ver = $this->input->post('vertical');
		$tmpname = $this->input->post('tmpname');
		$tmpath = $this->input->post('modlname');
		$width = get_tmp_width($tmpath);
		$insertsql = 'INSERT INTO res (shopid,time,content,width,tmpname,staute,tmpath,ver) VALUES ("'.$_SESSION["shopid"].'","'.$time.'","'.$htmlcontent.'","'.$width.'","'.$tmpname.'","'.$tmpath.'","'.$ver.'")';
		
        $insertsql = "INSERT INTO res (shopid,time,content,width,tmpname,staute,tmpath,ver) VALUES (
        \"{$_SESSION["shopid"]}\",\"{$time}\",\"{$htmlcontent}\",\"{$width}\",\"{$tmpname}\",0,\"{$tmpath}\",\"{$ver}\")";
        //$this->db->query($insertsql);
    }
	
*/	
	
	

    public function joinmemeber() {

        $this->memmbers->handle_database_info();
    }
	
	
	

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */